package com.example.secondhandsysapi.Mapper;


import com.example.secondhandsysapi.Entity.UserInfo;
import com.example.secondhandsysapi.Vo.GenderCount;
import com.example.secondhandsysapi.Vo.VGC;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.sql.Date;
import java.util.List;

@Mapper
public interface UserInfoMapper {

    @Select("select user_id,password from user_info where user_id=#{user_id} and password=#{password}")
    Integer LoginBackend(UserInfo userInfo);

    //获取所有用户的详细信息
    @Select("select * from user_info")
    List<UserInfo> getUserDetailInfo( );


    //根据用户id查详细信息
    @Select("select * from user_info where user_id = #{user_id}")
    List<UserInfo> getUserDetailInfoByID1(@Param("user_id") Integer user_id);

    @Select("select * from user_info where user_id = #{user_id}")
    UserInfo getUserDetailInfoByID(@Param("user_id") Integer user_id);

    //根据用户name模糊查询用户信息
    @Select("select * from user_info where user_name like '%${user_name}%'")
    List<UserInfo> getUserDetailInfoByName(@Param("user_name") String  user_name);
    @Select("select * from user_info where (user_id = #{user_id} and user_name like '%${user_name}%')")
    List<UserInfo> getUserDetailInfo1(@Param("user_id") Integer user_id,@Param("user_name") String  user_name);


    //获取新用户的数量
    @Select("SELECT COUNT(*)  FROM user_info WHERE registration_date like '%${registration_date}%'")
    Integer findNewUser(@Param("registration_date") Date registration_date);



    //select user_id,user_name,user_image,selfIntro,last_modified_time,check_status,check_info from user_info where check_status = 0 AND (user_id = #{user_id} or user_name like '%${user_name}%'
    //获取用户信息修改后进行审核的内容
    @Select("select user_id,user_name,user_image,selfIntro,last_modified_time,check_status,check_info from user_info where check_status = 0 AND (user_id = #{user_id} and user_name like '%${user_name}%')")
    List<UserInfo> getAllUpdateUserInfo(@Param("user_id") Integer user_id, @Param("user_name") String user_name);
    @Select("select user_id,user_name,user_image,selfIntro,last_modified_time,check_status,check_info from user_info where check_status = 0 ")
    List<UserInfo> getAllUpdateUserInfo1();
    @Select("select user_id,user_name,user_image,selfIntro,last_modified_time,check_status,check_info from user_info where check_status = 0 AND user_name like '%${user_name}%' ")
    List<UserInfo> getAllUpdateUserInfoByName(@Param("user_name") String user_name);
    @Select("select user_id,user_name,user_image,selfIntro,last_modified_time,check_status,check_info from user_info where check_status = 0 AND user_id = #{user_id} ")
    List<UserInfo> getAllUpdateUserInfoById(@Param("user_id") Integer user_id);

    //对status进行修改
    @Select("UPDATE user_info SET check_status =null WHERE user_id = #{user_id}")
    Integer updateStatus(@Param("user_id") Integer user_id);


    //对拒绝填写的备注进行保存
    @Select("UPDATE user_info SET check_info = #{check_info},check_status = 1 WHERE user_id=#{user_id}")
    Integer updateCheck_Info(@Param("check_info") String check_info,@Param("user_id") Integer user_id );

    @Update("update user_info set user_name=#{user_name},password=#{password},gender=#{gender},email=#{email},birthday=#{birthday},phone=#{phone},user_image=#{user_image},address=#{address},selfintro=#{selfintro},check_status=0 where user_id=#{user_id}")
    Integer updateUserInfo(UserInfo userInfo);




    //获取用户的男女比例
    @Select("SELECT CASE\n" +
            "    WHEN gender = 0 THEN '女'\n" +
            "    WHEN gender = 1 THEN '男'\n" +
            "END AS gender, COUNT(*) as val FROM user_info GROUP BY gender\n")
      List<VGC>  getUserGenderCount();

    //插入注册的商品用户信息
    @Insert("insert into user_info (user_name,user_id,email,password,role)   values(#{user_name},#{user_id},#{email},#{password},1)")
    Integer insertUserInfo(UserInfo userInfo);

}
